package com.sunfeng.jksj.p24;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2022/3/2  8:42
 */
public class Demo01 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // 跑任务
        CompletableFuture.runAsync(()->{
            System.out.println("我是runAsync");
        });
        // 创建对象
        CompletableFuture<String> stringCompletableFuture = CompletableFuture.supplyAsync(() -> "x");

        CompletableFuture.supplyAsync(() -> "x").thenAccept(System.out::println);

        try {
            String s = stringCompletableFuture.get();
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        CompletableFuture<String> singing = CompletableFuture.completedFuture("singing");

        CompletableFuture<Object> objectCompletableFuture = CompletableFuture.anyOf(stringCompletableFuture, singing);

        objectCompletableFuture.get();
    }
}
